// pages/xiaodangan/xiaodangan.js
const app = getApp();
var njzxw = require('../../utils/njzxw.js');
var url = require('../../utils/url.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    njzxw.addSubmit({
      page: this,
      url: url.userArchivesInfo.save,
      verify: function (b) {
        console.log(b);
        
        if ($this.data.index == 0) {
          return "请输入选择分组";
        }
        b['group_id'] = $this.data.group[$this.data.index].id;
        b['resouce_id'] = $this.data.file_id;
        b['id'] = $this.data.id;
        return b;
      },
      fun: function () {
        $this.setData({
          groupName: '',
          index: 0,
          showDeleteGroup: false,
          fromData: {},
          file: [],
          file_id: null,
        });
      }
    });
  },
  blood_sugar:function(e,data){
    console.log('===',data);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var $this = this;
    njzxw.initFun(this);
    njzxw.addSubmit({
      page: this,
      url: url.userArchivesInfo.save,
      verify: function (b) {
        var model = "";
        for(var key in b){
          model = key.substring(key.lastIndexOf('_') + 1, key.length);
          b[key.substring(0,key.lastIndexOf('_'))] = b[key];
        }
        if (njzxw.isEmpty(b.blood_sugar) && njzxw.isEmpty(b.blood_pressure) && njzxw.isEmpty(b.blood_pressure_szy)){
          return "血糖值、收缩压、舒张压必须添加一个哦";
        }

        if (njzxw.isEmpty(b.blood_sugar)){
          b.blood_sugar = null;
        }
        if (njzxw.isEmpty(b.blood_pressure)) {
          b.blood_pressure = null;
        }
          if (njzxw.isEmpty(b.blood_pressure_szy)) {
              b.blood_pressure_szy = null;
          }

        b[model] = {};
        b[model]['blood_sugar'] = b.blood_sugar;
        b[model]['blood_pressure'] = b.blood_pressure;
        b[model]['blood_pressure_szy'] = b.blood_pressure_szy;
        console.log('model:' + model);
        b.type = model == 'kf' ? 1 : model == 'zch' ? 2 : model == 'wcq' ? 3 : model == 'wch' ? 4 : model == 'wwcq' ? 5 : model == 'wwch' ? 6 : model == 'sq' ? 7:0;

        if (b.type == 0){
          return "未知错误，请重新进入小程序";
        }

        return b;
      }
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var $this = this;
    njzxw.ajax({
      url:url.userArchivesInfo.getOperToDay,
      isLoad:true,
      fun:function(a,b){
        wx.hideLoading();
        $this.setData({
          fromData:b.data.data
        });
      }
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})